package com.demo.service.dataManagement;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;


/**
 * @Classname TimelineService
 * @Description TODO
 * @Date 2020/3/18 17:23
 * @Created by yuanhang
 */
public class TimelineService {

    public Record tree() {
        Record record = new Record().set("id", null).set("title", "朝代").set("spread", true).set("disabled", true);
        this.recursion(record);
        return record;
    }

    public void recursion(Record record) {
        Kv cond = Kv.by("parentId", record.getInt("id"));
        List<Record> recordList = Db.template("timeline.child", cond).find();
        if (recordList.size() > 0) record.set("children", recordList);
        for (Record rec : recordList) {
            rec.set("spread", true);
            this.recursion(rec);
        }
    }

}
